import React from 'react';

class CarList extends React.Component{

	removeFromCar(id){
		this.props.removeFromCar({
			type:"RM_FROM_CAR",
			id:id
		})
	}

	render(){
		var that=this;
		console.log( this.props.carlist);
		var tocarlist;
		if(this.props.carlist.length>0){
			 tocarlist = this.props.carlist.map( (item, index) => (
	            <li key={index}>
	            	<span>{item.title}</span>
	            	<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
	            	<span>{item.price}</span>
	            	<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
	            	<span>{item.inventory}</span>
	            	<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
	            	<button onClick={that.removeFromCar.bind(that,item.id)}>移出购物车</button>
	            </li>
        	))
		}else{
			tocarlist=null;
		}
		
        
		//var list=this.getData();
		// console.log(list);
		return(
			<div>
				<h3>购物车</h3>
				{tocarlist}
			</div>
		)
	}
}

export default CarList;